import { confidentAudit} from '../../../../api/api';

Page({
  /**
   * 页面的初始数据
   */
  data: {
    type:'0',
    fileList: [],
    loading: false,
  },
  /**
   * 文件模式
   */
  chooseFile1(){
    wx.chooseMessageFile({
      count: 1,
      type: 'file',
      success: (res) => {
        wx.showToast({
          title: '上传中',
          icon: 'loading',
          duration: 2000,
          mask: "true"
        })
        const { tempFiles } = res;
        const file = tempFiles[0];
        const { fileList } = this.data;
        fileList.push(file);
        this.setData({
          fileList: fileList,
        });
      },
    });
  },
  submitFile1(){
    wx.showLoading({
      title: '加载中',
      mask: "true"
    })
    this.setData({
      loading: true,
    });
    const { fileList } = this.data;
    const filePath = fileList[0].path;
    wx.uploadFile({
      // url: 'http://110.40.174.156:8998/cdAudit/fileAudit', // 替换为你的审核接口地址
      url: 'http://127.0.0.1:8998/cdAudit/wxPDFAudit', // 替换为你的审核接口地址
      filePath: filePath,
      name: 'file',
      success: (res) => {
        wx.hideLoading();
        console.log(res.data);
        const data = JSON.parse(res.data);
        if (data) {
          this.setData({
            loading: false,
          });
          wx.navigateTo({
            url: '/pages/main/ConfidentialAudit/report/report?data=' + JSON.stringify(JSON.parse(res.data).data)
          });
        }

        wx.clearStorage()
        console.log("缓存清除成功");
      },
      fail: (err) => {
        console.log("上传文件类型不符合要求");
      },
    });
  },
  /**
   * 手写字模式
   */
  chooseFile2(){
    wx.chooseMessageFile({
      count: 1,
      type: 'file',
      success: (res) => {
        wx.showToast({
          title: '上传中',
          icon: 'loading',
          duration: 1000,
          mask: "true"
        })
        const { tempFiles } = res;
        const file = tempFiles[0];
        const { fileList } = this.data;
        fileList.push(file);
        this.setData({
          fileList: fileList,
        });
      },
    });
  },
  submitFile2(){
    wx.showLoading({
      title: '加载中',
      mask: "true"
    })
    this.setData({
      loading: true,
    });
    const { fileList } = this.data;
    const filePath = fileList[0].path;
    wx.uploadFile({
      // url: 'http://110.40.174.156:8998/cdAudit/wxImgAudit', // 替换为你的审核接口地址
      url: 'http://127.0.0.1:8998/cdAudit/wxImgAudit', // 替换为你的审核接口地址
      filePath: filePath,
      name: 'file',
      success: (res) => {
        wx.hideLoading();
        console.log(res.data);
        const data = JSON.parse(res.data);
        if (data) {
          this.setData({
            loading: false,
          });
          wx.navigateTo({
            url: '/pages/main/ConfidentialAudit/report/report?data=' + JSON.stringify(JSON.parse(res.data).data)
          });
        }
        wx.clearStorage()
        console.log("缓存清除成功");
      },
      fail: (err) => {
        this.setData({
          loading: false,
        });
        console.log(err);
      },
    });
  },

  //单选按钮值发生变化
  handleTypeChange: function(e){
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    this.setData({
      type: e.detail.value
    })
    console.log(this.data.type);
  },
})
